// ### 连接数据库
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/express_takeout01'); // 连接
const conn = mongoose.connection; // 连接对象

conn.on('connected', function () { // 监听连接成功方法
  console.log('数据库连接成功!');
});

// ### 得到对应特定集合的Model
const userSchema = mongoose.Schema({
  'name': {type: String},
  'pwd': {type: String},
  'phone': {'type': String}
});
UserModel = mongoose.model('user', userSchema);

module.exports = {
  getModel(name) {
    return mongoose.model(name);
  }
}
